1. /* sxfbexpx.cpp by K.Tsuru */
  2. // function ID 5205 BRADIX(reference)
  3. /*****************
  4. SDecimal class
  5. exp(x) by series
  6. ******************/
  7. #ifndef SN_H
  8. #include "sn.h"
  9. #endif
  10. static const char* func = "BexpSeries";
  11. SDecimal BexpSeries(const SDouble& x){
  12. int e = x.NetRdxExp();
  13. int xsgn;
  14. if( (xsgn = x.Sign(5205)) == 0) return x;
  15. if( e > 0){ // x > 1
  16. x.SetError(x.OUT_OF_RANGE, func, 5205);
  17. }
  18. SDecimal sum(1.0), xf, delta;
  19. xf = xf.ConvToBin(x);
  20. ulong mt = delta.SlOpMaxValue(), k = 2;
  21. // sum = 1 + x;
  22. if(xsgn < 0 ){
  23. xf.ChangeSign(); XXSub(sum, xf, sum); // xf = |x|
  24. } else XXAdd(sum, xf, sum);
  25. delta = xf;
  26. while(delta.Sign()){
  27. XsDiv(delta*xf, k, delta);
  28. if((xsgn < 0) && (k & 1)) XXSub(sum, delta, sum);
  29. else XXAdd(sum, delta, sum);
  30. if( (k++) >= mt ){
  31. sum.SetError(sum.NOT_CONVERGE, func, -5205);
  32. break;
  33. }
  34. }
  35. return sum;
  36. }

sxfbexpx.cpp : last modifiled at 2015/12/15 13:59:15(901 bytes)
created at 2015/12/22 16:09:56
The creation time of this html file is 2017/10/27 15:45:59 (Fri Oct 27 15:45:59 2017).